package com.party.admin.web.controller.poster;

import com.party.admin.biz.crowdfund.PaintProjectPosterBiz;
import com.party.admin.web.dto.AjaxResult;
import com.party.admin.web.dto.output.crowdfund.ProjectPosterOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: party
 * @description: 海报控制器
 * @author: Hua Qunhao
 * @create: 2019-01-31 14:33
 **/
@Controller
@RequestMapping(value = "/PosterController")
public class PosterController {

    @Autowired
    private PaintProjectPosterBiz paintProjectPosterBiz;


    Logger logger = LoggerFactory.getLogger(getClass());



    /** 
    * @Description:福字海报VIEW
    * @Param: [] 
    * @return: org.springframework.web.servlet.ModelAndView 
    * @Author: Hua Qunhao
    * @Date: 2019-01-31-0031 
    */
    @RequestMapping("/view")
    public ModelAndView view() {
        ModelAndView mv = new ModelAndView("poster/fuzPosterView");
        return mv;
    }



    /**
     * @Description:生成福字海报
     * @Param: [request]
     * @return: com.party.admin.web.dto.AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019-01-31-0031
     */
    @RequestMapping(value = "/createFuzPoster")
    @ResponseBody
    public AjaxResult createFuzPoster(String memberUsername, String qccode, String logo, HttpServletRequest request) {

        byte[] bytes = null;
        String posterPath = "";
        ProjectPosterOutput posterOutput = new ProjectPosterOutput();
        posterOutput.setNickName(memberUsername);
        posterOutput.setLogo(logo);
        posterOutput.setPersonalQrCodeUrl(qccode);
        try {
            bytes = paintProjectPosterBiz.blessingFontPoster(posterOutput);

            try {
                String fileName =System.currentTimeMillis()+"";
                posterPath = String.format("/%s/%s/", "blessingPosterTempFile", "blessingPoster");

                posterPath = paintProjectPosterBiz.PosterUploadCI(fileName, posterPath, bytes);
            } catch (Exception e) {
                logger.error("福字海报上传腾讯云异常", e);
            }

        } catch (Exception ee) {
            logger.error("福字海报制作异常", ee);
            return  AjaxResult.error("福字海报制作异常,请多次尝试，如若不能请电联本人18124081240");
        }
      return   AjaxResult.success(posterPath);
    }
}

